<?php
/*
	我的退款记录
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
if($_RQ['op']=='main'){
	$pramas=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'mid'=>$_SESSION['uid']);
	if(isset($_RQ['status'])){
		$pramas['status']=$_RQ['status'];
	}	
	$list=pdo_getall('jy_zhongchou_withdraw',$pramas,'','createtime desc');
	$list=array();
	if($list){
		foreach($list as &$item){
		$project=pdo_get('jy_zhongchou_project',array('id'=>$item['pid'],'uniacid'=>$_SESSION['uniacid']));
		$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		$item['project']=$project;
		if($item['status']==0){
			$item['status']='待审核';
		}elseif($item['status']==1){
			$item['status']='已退款';
		}else{
			$item['status']='审核未通过';
		}
		}
	}
	$return['list']=$list;
	exi($return);

}

//申请退款
if($_RQ['op']=='withdraw'){
	$id=$_RQ['id'];
	if(!$id){
		exi('未找到需要退款的订单！','error');
	}
	$paylog=pdo_get('jy_zhongchou_paylog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'pid'=>$paylog['pid'],
			'payid'=>$id,
			'reason'=>$postdata['reason'],
			'type'=>$postdata['type'],
			'money'=>$paylog['fee'],
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_zhongchou_withdraw',$insert);
		exi('已提交申请');
	}
	$return['post']=array();
	$return['paylog']=$paylog;
	}
	
